home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 408 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: gate.net!pslfl2-23
  2. From: bhutto@gate.net (William Hutto)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: ugly constants and header files
  5. Date: 5 Jan 1996 02:44:43 GMT
  6. Organization: CyberGate, Inc.
  7. Message-ID: <4ci3ar$f84@news.gate.net>
  8. References: <1996Jan3.155754.111142@kuhub.cc.ukans.edu>
  9. NNTP-Posting-Host: pslfl2-44.gate.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <1996Jan3.155754.111142@kuhub.cc.ukans.edu>,
  13.    anh@kuhub.cc.ukans.edu wrote:
  14. >Hello,
  15. >
  16. >I have a list of constants, some defined using #define, some are string 
  17. >constants a la char *gSuperStrings[]={"aa","bb"};
  18. >
  19. >These constants are used by multiple modules which are linked together to 
  20. >a program. However, I have more than one program using these constants,
  21. >hence I put the constants in a header file. I know it is ugly to put
  22. >definitions in a header file.
  23. >
  24. >My current solution is to change all the #define to integer constants and 
  25. >to keep 2 files:
  26. >
  27. >my_const.h        --- To be included only once (perferably by the main() 
  28. >              module). Definitions
  29. >
  30. >my_ext.h          --- To be included by any modules using the constants.
  31. >                      Declarations.
  32. >
  33. >Is this the best solution? Are there any other way?
  34. >
  35. >Thank-you,
  36. >Anh
  37.  
  38. Put your #define's in a header file. Put your _const_ variables in a source 
  39. file by themselves if you want. If they're to be truely global, declare them 
  40. _extern_ in a header file.
  41.  
  42. Bill
  43.  
  44. "Whatcha got on?...Your mind?"
  45.